#include <QHash>
#include "icon-store.h"
#include "standard-paths.h"


QHash<QPair<IconStore::IconType,int>,QIcon> IconStore::iconStorage;
QHash<IconStore::IconType,QString> IconStore::iconFileNameStorage;


QIcon IconStore::icon (const IconStore::IconType iconType, const int size)
{
    QIcon icon = iconStorage.value(qMakePair(iconType, size));
    if (icon.isNull())
    {
        icon = QIcon(StandardPaths::imagesPath() + iconFileName(iconType, size));
        iconStorage.insert(qMakePair(iconType, size), icon);
    }

    return icon;
}


QPixmap IconStore::pixmap (const IconStore::IconType iconType, const int size)
{
    return icon(iconType, size).pixmap(size, size);
}


QString IconStore::iconFileName (const IconStore::IconType iconType, const int size)
{
    if (iconFileNameStorage.isEmpty())
        populateIconFileNameStorage();

    return QString::number(size) + "x" + QString::number(size) + "/" + iconFileNameStorage.value(iconType);
}


void IconStore::populateIconFileNameStorage()
{
    iconFileNameStorage.insert(ArrowRight, "arrow-right.png");
    iconFileNameStorage.insert(DialogCritical, "dialog-critical.png");
    iconFileNameStorage.insert(DialogHint, "dialog-hint.png");
    iconFileNameStorage.insert(DialogInformation, "dialog-information.png");
    iconFileNameStorage.insert(DialogWarning, "dialog-warning.png");
    iconFileNameStorage.insert(DocumentEdit, "document-edit.png");
    iconFileNameStorage.insert(DocumentExport, "document-export.png");
    iconFileNameStorage.insert(DocumentImport, "document-import.png");
    iconFileNameStorage.insert(ListAdd, "list-add.png");
    iconFileNameStorage.insert(ListRemove, "list-remove.png");
    iconFileNameStorage.insert(PreferencesSystem, "preferences-system.png");
    iconFileNameStorage.insert(ServerDatabase, "server-database.png");
    iconFileNameStorage.insert(StatusOk, "status-ok.png");
    iconFileNameStorage.insert(StatusRejected, "status-rejected.png");
    iconFileNameStorage.insert(StatusRunning, "status-running.png");
    iconFileNameStorage.insert(SystemRun, "system-run.png");
}
